<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="90%" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false">
        <el-container>
            <el-main>
                <el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right" style="height:750px;overflow:auto">
                    <el-row :gutter="1">
                        <el-col :span="8">
                            <el-form-item label="工厂货号" prop="factory_number">
                                <el-input v-model="form.factory_number" placeholder="请输入工厂货号" clearable @input="materAdd"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="颜色" prop="colour">
                                <!-- <el-select v-model="form.colour" @change="change" placeholder="请选择" style="width:100%">
                                    <el-option v-for="item in colorList" :key="item.id" :label="item.title" :value="item.id"></el-option>
                                </el-select> -->
                                <el-input v-model="form.colour" placeholder="请输入颜色" clearable></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="主色/加色" prop="color_type">
                                <el-select v-model="form.color_type" placeholder="请选择主色/加色" style="width:100%">
                                    <el-option label="主色" :value="1"></el-option>
                                    <el-option label="加色" :value="2"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="1">
                        <el-col :span="8">
                            <el-form-item label="商品款式" prop="style_id">
                                <el-select v-model="form.style_id" filterable placeholder="请选择商品类别" style="width:100%" clearable>
                                    <el-option v-for="item in styleList" :key="item.id" :label="item.title" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="商品类别" prop="cate_id">
                                <el-select v-model="form.cate_id" @change="typeChange" filterable placeholder="请选择商品类别" style="width:100%" clearable>
                                    <el-option v-for="item in proType" :key="item.id" :label="item.title" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="样衣尺寸" prop="sample_size">
                                <el-select v-model="form.sample_size" filterable placeholder="请选择样衣尺寸" style="width:100%" clearable @change="sampleSizeChange">
                                    <el-option v-for="(item,index) in paper.sample_clothing_arr" :key="index" :label="item" :value="item" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="1">
                        <el-col :span="8">
                            <el-form-item label="成分" prop="component">
                                <el-select v-model="form.component" filterable placeholder="请选择商品类别" style="width:100%" clearable>
                                    <el-option v-for="item in componentList" :key="item.id" :label="item.component_name" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="样衣成品(g)" prop="sample_weight">
                                <el-input v-model="form.sample_weight" placeholder="请输入样衣成品克重" clearable @input="weightInput"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="针种" prop="needle_seed">
                                <el-select v-model="form.needle_seed" filterable placeholder="请选择针种" style="width:100%" multiple clearable>
                                    <el-option v-for="item in needleList" :key="item.id" :label="item.title" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="1">
                        <el-col :span="8">
                            <el-form-item label="吓数放码人" prop="scare_staff">
                                <el-select v-model="form.scare_staff" filterable placeholder="请选择吓数放码人" style="width:100%" clearable>
                                    <el-option v-for="item in scareList" :key="item.id" :label="item.name" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="画花放码人" prop="painted_staff">
                                <el-select v-model="form.painted_staff" filterable placeholder="请选择画花放码人" style="width:100%" clearable>
                                    <el-option v-for="item in paintedList" :key="item.id" :label="item.name" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="是否套装" prop="painted_staff" class="color">
                                <div style="display:flex">
                                    <el-switch v-model="form.is_suit" :active-value="1" :inactive-value="0" @change="switchChange"></el-switch>
                                    <div style="display:flex;margin-left:10px;" v-if="form.is_suit==1">
                                        <el-select v-model="form.suit_num" filterable placeholder="请选择件套" style="width:100px" clearable :disabled="(mode=='edit' || mode=='color') && is_suit==1" @change="suitChange">
                                            <el-option v-for="item in 10" :key="item" :label="item" :value="item" />
                                        </el-select>
                                        <span>件套</span>
                                    </div>
                                </div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-col :span="8">
                        <el-form-item label="洗水方式" prop="washing_method" >
                            <el-select v-model="form.washing_method" clearable style="width: 100%" filterable placeholder="请选择">
                                <el-option v-for="item in washList" :key="item.id" :label="item.title" :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <!-- 克重 -->
                    <el-col :span="24">
                        <div style="display: flex;flex-wrap: wrap">
                            <div v-for="(item,index) in form.suitGross" :key="index" style="margin:20px">
                                <el-form-item :label="'克重' + item.suit_name" prop="gross_weight">
                                    <sc-form-table ref="table" v-model="item.gross_weight" :addTemplate="weight" hideAdd hideDelete placeholder="暂无数据">
                                        <el-table-column prop="size" label="尺码" align="center" width="90">
                                            <template #default="scope">
                                                <!-- <el-input v-model="scope.row.size" placeholder="请输入重量"></el-input> -->
                                                <div>{{scope.row.size}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="weight" label="毛重(g)" align="center" width="150">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.weight" placeholder="请输入重量"></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="loom_time" label="织机时间" align="center" width="150">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.loom_time" placeholder="请输入织机时间">
                                                    <template #append>分钟</template>
                                                </el-input>
                                            </template>
                                        </el-table-column>
                                    </sc-form-table>
                                </el-form-item>
                            </div>
                        </div>
                    </el-col>
                    <!-- 商品图片 -->
                    <el-row :gutter="1">
                        <el-col :span="16">
                            <el-form-item label="商品图片">
                                <sc-upload-multiple v-model="form.goods_image_item" draggable></sc-upload-multiple>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="尺寸图片">
                                <sc-upload v-model="form.size_image" draggable ></sc-upload>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <!-- 客户 -->
                    <el-col :span="24">
                        <el-form-item label="客户信息" prop="custom_data">
                            <sc-form-table ref="table" v-model="form.custom_data" :addTemplate="addTemplate" placeholder="暂无数据">
                                <el-table-column prop="custom_id" label="客户" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.custom_id" @change="custChange(scope.row)" placeholder="请选择" clearable filterable>
                                            <el-option v-for="item in customList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="brand_id" label="品牌" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.brand_id" placeholder="请选择" clearable filterable>
                                            <el-option v-for="item in scope.row.pingType" :key="item.id" :label="item.brand_name" :value="item.id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="design_style_number" label="设计款号" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.design_style_number" placeholder="请输入设计款号"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="custom_style_number" label="客户款号" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.custom_style_number" placeholder="请输入客户款号"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="price" label="客户价格" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.price" placeholder="请输入客户价格"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="spu" label="SPU" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.spu" placeholder="请输入SPU"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="skc" label="SKC" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.skc" placeholder="请输入SKC"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="sample_tracking" label="样品跟单" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.sample_tracking" @change="change" placeholder="请选择" clearable>
                                            <el-option v-for="item in yangList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="order_tracking" label="大货跟单" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.order_tracking" placeholder="请选择" clearable>
                                            <el-option v-for="item in staffList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                            </sc-form-table>
                        </el-form-item>
                    </el-col>
                    <!-- 物料配比表 -- 套装 -->
                    <el-col :span="24">
                        <div style="display: flex;flex-wrap: wrap">
                            <div v-for="(item,index) in form.suitProportioning" :key="index" style="margin:20px;border: 1px solid red">
                                <el-form-item :label="'物料配比表' + item.suit_name" prop="material_proportioning">
                                    <sc-form-table ref="table" v-model="item.material_proportioning" :addTemplate="material_proportioning" placeholder="暂无数据" drag-sort showSummary @son="materAdd" height="250">
                                        <el-table-column label="工厂货号" align="center" width="120">
                                            <template #default="scope">
                                                <div>{{scope.row.factory_number}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="工序" align="center" width="120">
                                            <template #default="scope">
                                                <el-select v-model="scope.row.two_process_id" placeholder="请选择" clearable @change="two_process_change(item,scope.row.two_process_id)">
                                                    <el-option v-for="item1 in goodsProList" :key="item1.id" :label="item1.title" :value="item1.id"></el-option>
                                                </el-select>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="是否主工序" align="center" width="120">
                                            <template #default="scope">
                                                <el-switch v-model="scope.row.is_main_process " :active-value="1" :inactive-value="0" @change="mainChange(item.material_proportioning,scope.$index)"></el-switch>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="色位" align="center" width="120">
                                            <template #default="scope">
                                                <el-select v-model="scope.row.color_position" placeholder="请选择" filterable @change="colorChange(item,index)">
                                                    <el-option v-for="item1 in colorPosition" :key="item1.id" :label="item1.title" :value="item1.id"></el-option>
                                                </el-select>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="ratio" label="比例" align="center" width="120">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.ratio" type="number" placeholder="请输入比例" @mousewheel.prevent></el-input>
                                            </template>
                                        </el-table-column>
                                    </sc-form-table>
                                </el-form-item>
                                <el-form-item :label="'毛料'+item.suit_name" prop="material_spec">
                                    <sc-form-table ref="table" v-model="item.material_spec" :addTemplate="material" placeholder="暂无数据" hideAdd show-summary>
                                        <el-table-column label="色位" align="center" width="80">
                                            <template #default="scope">
                                                {{ scope.row.color_position_title }}
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" width="50">
                                            <template #default="scope">
                                                <el-button v-if="!scope.row.material_id" type="primary" icon="el-icon-plus" size="small" plain circle @click="openWu(item,index,scope.row,scope.$index)"></el-button>
                                                <el-button v-else type="warning" icon="el-icon-refresh" size="small" plain circle @click="openWu(item,index,scope.row,scope.$index)"></el-button>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="apply_name" label="供应商" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.apply_name}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="skc" label="毛料skc" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.skc}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="material_name" label="毛料名称" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.material_name}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="reference_price" label="参考单价" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.reference_price" placeholder="参考单价" @input="matColorChange(item,scope.row)"></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="色号" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.color_number}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="colour" label="颜色" align="center">
                                            <template #default="scope">
                                                <div v-if="scope.row.colour">{{scope.row.colour}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="图片" align="center">
                                            <template #default="scope">
                                                <el-image style="width:50px;height:50px" :src="scope.row.image" :preview-src-list="scope.row.image" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="loss_ratio" label="损耗比" align="center">
                                            <template #default="scope">
                                                <div style="display:flex;align-items:center">
                                                    <el-input v-model="scope.row.loss_ratio" placeholder="损耗比"></el-input>
                                                    <div style="margin-left:5px">%</div>
                                                </div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="estimated_price" label="预计毛价" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.estimated_price" placeholder="预计毛价" readonly></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column width="75" align="center">
                                            <template #default="scope">
                                                <el-button type="primary" size="small" @click="matColorChange(item,scope.row)">计算</el-button>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="备注" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.remark" placeholder="备注"></el-input>
                                            </template>
                                        </el-table-column>
                                    </sc-form-table>
                                </el-form-item>
                                <el-form-item :label="'辅料'+item.suit_name" prop="accessories_data">
                                    <el-button type="primary" size="small" icon="el-icon-plus" @click="openWuFu(item,index)">新增辅料</el-button>
                                    <sc-form-table ref="table" v-model="item.accessories_data" :addTemplate="material" placeholder="暂无数据" hideAdd @sons="refInputFu(item)">
                                        <el-table-column label="工序" align="center">
                                            <template #default="scope">
                                                <el-select v-model="scope.row.two_process_id" placeholder="请选择" clearable>
                                                    <el-option v-for="item in twiceList" :key="item.id" :label="item.title" :value="item.id"></el-option>
                                                </el-select>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="material_name" label="辅料名称" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.material_name}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="apply_name" label="供应商" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.apply_name}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="skc" label="辅料skc" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.skc}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="color_number" label="色号" align="center">
                                            <template #default="scope">
                                                <div>{{scope.row.color_number}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="colour" label="颜色" align="center">
                                            <template #default="scope">
                                                <div v-if="scope.row.colour">{{scope.row.colour}}</div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="image" label="图片" align="center">
                                            <template #default="scope">
                                                <el-image style="width:50px;height:50px" :src="scope.row.image" :preview-src-list="scope.row.image" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="reference_price" label="参考单价" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.reference_price" placeholder="参考单价" @input="refInputFu(item)"></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="ratio" label="用量" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.ratio" placeholder="请输入用量" @input="refInputFu(item)"></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="unit" label="单位" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.unit" placeholder="请输入单位" readonly></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="loss_ratio" label="损耗" align="center">
                                            <template #default="scope">
                                                <div style="display:flex;align-items:center">
                                                    <el-input v-model="scope.row.loss_ratio" placeholder="请输入损耗" @input="refInputFu(item)"></el-input>
                                                    <div style="margin-left:5px">%</div>
                                                </div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="estimated_price" label="预计辅料价" align="center">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.estimated_price" placeholder="预计辅料价" readonly></el-input>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="remark" label="备注">
                                            <template #default="scope">
                                                <el-input v-model="scope.row.remark" placeholder="请输入备注"></el-input>
                                            </template>
                                        </el-table-column>
                                    </sc-form-table>
                                </el-form-item>
                            </div>
                        </div>
                    </el-col>
                    <!-- 工序 -->
                    <el-col :span="24">
                        <el-form-item label="工序信息" prop="process_data">
                            <sc-form-table ref="table" v-model="form.process_data" :addTemplate="process" placeholder="暂无数据" drag-sort showSummary :summary-method="processMethod" @sons="proInput">
                                <el-table-column width="90" align="center">
                                    <template #default="scope">
                                        <el-button type="primary" size="small" icon="el-icon-search" @click="openGong(scope.row,scope.$index)"></el-button>
                                    </template>
                                </el-table-column>
                                <el-table-column label="一级工序" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.process_id" @change="changeGong(scope.row)" placeholder="请选择" clearable>
                                            <el-option v-for="item in processList" :key="item.id" :label="item.title" :value="item.id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="GongxuSon" label="二级工序" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.two_process_id" placeholder="请选择" clearable @change="twoProChange(scope.row)">
                                            <el-option v-for="item in scope.row.GongxuSon" :key="item.id" :label="item.title" :value="item.id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="unit_price" label="工序单价(元/件)" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.unit_price" placeholder="请输入工序单价"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="due_price" label="预计成本(元/件)" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.due_price" placeholder="请输入预计成本" @input="proInput"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column label="排序" prop="sort">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.sort"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column label="备注">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.remark" placeholder="请输入备注"></el-input>
                                    </template>
                                </el-table-column>
                            </sc-form-table>
                        </el-form-item>
                    </el-col>
                    <!-- 尺寸 -->
                    <el-col :span="24">
                        <el-form-item label="尺寸信息" prop="goods_location_data">
                            <sc-form-table ref="table" v-model="form.goods_location_data" :addTemplate="location" placeholder="暂无数据" @son="rowAdd">
                                <el-table-column prop="location_id" label="部位" align="center">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.location_id" placeholder="请选择" @change="locationChange(scope.row, scope.$index)" clearable filterable>
                                            <el-option v-for="item in positionList" :key="item.id" :label="item.title" :value="item.id"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="size_latitude" label="尺寸纬度" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.size_latitude" readonly></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="measure_method" label="量法" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.measure_method"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="yangyi_size" label="样衣尺寸" align="center">
                                    <template #default="scope">
                                    <el-input v-model="scope.row.yangyi_size" @input="input(scope.row, scope.$index)"></el-input>
                                </template>
                                </el-table-column>
                                <el-table-column prop="tiaoma" label="跳码" align="center" width="100">
                                    <template #default="scope">
                                        <div style="display:flex;align-items: center;">
                                            <el-input v-model="scope.row.tiaoma" @input="input(scope.row, scope.$index)"></el-input>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="dahuo_size" label="大货尺寸" align="center">
                                    <el-table-column align="center" v-for="(child,index) in location.dahuo_size" :key="index" :label="child.size_name" :prop="child.size">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.dahuo_size[index].size"></el-input>
                                        </template>
                                    </el-table-column>
                                </el-table-column>
                                <el-table-column prop="tolerance_range" label="允差范围" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.tolerance_range" readonly></el-input>
                                    </template>
                                </el-table-column>
                            </sc-form-table>
                        </el-form-item>
                    </el-col>
                    <!-- 纸样 -->
                    <el-col>
                        <el-form-item label="纸样">
                            <sc-upload-multiple v-model="form.paper_sample_url" draggable></sc-upload-multiple>
                        </el-form-item>
                    </el-col>
                    <!-- 画花 -->
                    <el-col>
                        <el-form-item label="画花">
                            <sc-upload-file v-model="form.ziliao_url" :limit="1" @file="before">
                                <el-button type="primary" icon="el-icon-upload">上传画花资料</el-button>
                            </sc-upload-file>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-main>
            <el-footer>
                <div style="display:flex;justify-content: end;">
                    <el-button @click="visible = false">取 消</el-button>
                    <el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
                </div>
            </el-footer>
        </el-container>
    <custom v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false" draggable :query="{category_id:this.type==1?1:2}"></custom>
    <gong v-if="gong.save" ref="gongDialog" @success="gongSuccess" @closed="gong.save = false" draggable></gong>
	</el-dialog>
</template>

<script>
import custom from './custom.vue';  //物料
import Gong from './gong.vue';      //工序
export default {
    components: { custom, Gong },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增商品',
				edit: '编辑商品',
				color: '加色',
				show: '查看'
			},
            dialog: {
				save: false
			},
            gong: {
				save: false
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				id: "",
				goods_name: "",
				goods_short_name: "",
                factory_number:"",
                washing_method : "",
				pinyin_code: "",
				unit_id: "",
				cate_id: "",
				goods_image: "",
				goods_image_item: "",
				desc: "",
				sort: "",
				is_suit: 0,
                system_disable: 0,
                suit_num:1,
				style_id: "",
				component: "",
				color_type: "",
				colour: "",
				sample_weight: "",
				sample_size: "",
                paper_sample_size:"",
				needle_seed: "",
				size_image: "",
				paper_sample_url: "",
				ziliao_url: "",
                ziliao_url_name:"",
                scare_staff:"",
                painted_staff:"",
                custom_data:[],         //客户信息
                goods_location_data:[], //商品部位
                gross_weight:[],        //商品尺码克重
                material_spec:[],       //物料信息
                process_data:[],        //工序信息
                material_proportioning:[],//物料配比表
                suitGross:[                //克重
                    {suit_name:"",factory:"",gross_weight:[]}
                ],
                suitProportioning:[       //配比表
                    {suit_name:"",factory:"",material_proportioning:[],},
                ],
			},
            is_suit:"",
            tiaoma:"",
            addTemplate:{custom_id:'',brand_id:'',custom_style_number:'',price:'',design_style_number:'',spu:'',skc:'',sample_tracking:'',order_tracking:''},
            material:{material_spec_code:"",ratio:"",loss_ratio:"",remark:"",},
            process:{process_id:"",two_process_id:"",sort:"",price:"",remark:"",staff_id:"",due_price:""},
            location:{location_id:"",size_latitude:"",measure_method:"",yangyi_size:"",zhiyang_size:"",tiaoma:"",tolerance_range:"",dahuo_size:[]},
            material_proportioning:{loss_ratio:0},
			//验证规则
			rules: {
                factory_number: [
					{ required: true, message: '请输入工厂货号' }
				],
                color_type: [
					{ required: true, message: '请选择主色/加色' }
				],
                style_id: [
					{ required: true, message: '请选择商品款式' }
				],
                cate_id: [
					{ required: true, message: '请选择商品类别' }
				],
                sample_size: [
					{ required: true, message: '请选择样衣尺寸' }
				],
                paper_sample_size: [
					{ required: true, message: '请选择纸样尺寸' }
				],
                washing_method : [
                    { required: true, message: '请选择洗水方式' }
                ],
            },
            proType:[],
            paper:[],
            pingType:[],//品牌
            customList:[],//客户
            styleList:[],//客户
            processList:[],//工序
            positionList:[],//部位
            needleList:[],//针种
            colorList:[],//颜色
            staffList:[],//大货跟单
            yangList:[],//样品跟单
            componentList:[],//成分
            goodsProList:[],
            type:"",
            scareList:[],//吓数员工
            paintedList:[],//画花员工
            washList:[],//洗水方式
            wuNumber:"",
            fuNumber:"",
            gongNumber:"",
            goods_material_estimated_price:"",
            Position:[],
            twiceList:[],
            newProcessList:[],
            newLoomTwoProcessList:[],
            newLoomTwoProcessIdList:[],
            colorPosition: [],
		}
	},
	mounted() {
        this.getType()
        this.getKeHu()
        this.getStyle()
        this.getProcess()
        this.getPosition()
        this.getNeedle()
        this.getColor()
        this.getStaff()
        this.getWash()
        this.getYang()
        this.getXia()
        this.getHua()
        this.getComponent()
        this.getColorPosition()
        this.getGoodsProcess()
        this.getTwiceProcess()
        this.getBasicProcess()
	},
	methods: {
        materAdd(){
            this.form.suitProportioning.map((item,index)=>{
                let symbols = []
                if(this.form.is_suit==1){
                    symbols = ["A", "B", "C", "D","E","F","G","H","I","J"]
                }else{
                    symbols = [""]
                }
                item.material_proportioning.map(item1=>{
                    item1.factory_number = this.form.factory_number + symbols[index]
                    item1.is_main_process = 0
                })
            })
        },
        two_process_change(item){
            console.log('item :>> ', item);
            let arr = []
            if(item.suit_name == "A"){
                item.material_proportioning.map(item1=>{
                    console.log('所有',item1);
                    let top = '_' + item1.two_process_id;
                    if(item1.two_process_id){
                        if (arr.indexOf(item1.two_process_id) == -1) {
                            arr.push(item1.two_process_id)
                        }
                        
                        if (top in this.newProcessList) {
                            console.log('存在');
                        } else {
                            let proTemp = {
                                process_id: 3,
                                two_process_id: item1.two_process_id,
                                GongxuSon: this.newLoomTwoProcessList,
                            };
                            this.form.process_data.push(proTemp);
                            this.newProcessList[top] = proTemp;
                        }
                    }
                })
                this.form.process_data.map((item1,index)=>{
                    if(item1.process_id == 3 && arr.indexOf(item1.two_process_id) == -1){
                        delete this.newProcessList['_' + item1.two_process_id]
                        this.form.process_data.splice(index,1)
                    }
                })
            }
        },
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		submit() {
            this.form.process_data.map((item,index)=>{
                item.sort = index+1
            })
            this.form.gross_weight = this.form.suitGross[0].gross_weight
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = [];
                    let a = (this.form.goods_image_item).split(",")
					this.form.goods_image = a[0]
                    if (this.mode=='edit') {
						res = await this.$API.goods.getGoods.edit.post(this.form);
					} else if(this.mode=='add' || this.mode=='color'){
						res = await this.$API.goods.getGoods.add.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 1) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", { type: 'error' })
					}
				} else {
					return false;
				}
			})
		},
        before(file){
            this.form.ziliao_url_name = file.name
        },
		//表单注入数据
		async setData(data,e) {
            if(e==1){
                this.form.color_type = data.color_type
            }
            if(e==2){
                this.mode='color'
                this.form.color_type = e
            }
			this.form.id = data.id
            var res = await this.$API.goods.getGoods.detail.get({id:data.id});
            this.form.factory_number = res.data.factory_number
			this.form.colour = res.data.colour
			this.form.washing_method = res.data.washing_method
			this.form.style_id = res.data.style_id
			this.form.cate_id = res.data.cate_id
			this.form.sample_size = res.data.sample_size
			this.form.paper_sample_size = res.data.paper_sample_size
			this.form.component = res.data.component==0?"":Number(res.data.component)
			this.form.sample_weight = res.data.sample_weight
			this.form.needle_seed = res.data.needle_seed
			this.form.scare_staff = Number(res.data.scare_staff)
			this.form.painted_staff = Number(res.data.painted_staff)
			this.form.gross_weight = res.data.gross_weight
			this.form.is_suit = res.data.is_suit
            this.is_suit = res.data.is_suit
			this.form.suit_num = res.data.suit_num
			this.form.goods_image_item = res.data.goods_image_item
			this.form.size_image = res.data.size_image_full_url
			this.form.custom_data = res.data.customList
            this.form.suitProportioning = res.data.suitProportioning
            res.data.suitProportioning.map(item=>{
                let table = []
                item.material_proportioning.map(item=>{ 
                    table.push({
                        factory_number:res.data.factory_number,
                        two_process_id:item.two_process_id,
                        color_position:item.color_position,
                        ratio:item.ratio,
                        loss_ratio:item.loss_ratio,
                    })
                })
                // 初始话物料配比下的毛料
                let material = []
                table.map(item=>[
                    this.colorPosition.map(item1=>{
                        if(item.color_position==item1.id){
                            material.push({
                                color_position:item1.id,
                                color_position_title:item1.title,
                            })
                        }
                    })
                ])
                material.map(item1=>{
                    let flag = false;
                    item.material_spec.map(item=>{
                        if(item.color_position==item1.color_position){
                            flag = true;
                        }
                    })
                    if(flag === false){
                        item.material_spec.push({
                            color_position:item1.color_position,
                            color_position_title:item1.color_position_title,
                        })
                    }
                })
            })
            this.form.suitGross = res.data.suitGross
            // 工序
            let processData = []
            res.data.goodsProcess.map(item=>{
                processData.push({
                    id:item.id,
                    process_id:item.process_id,
                    two_process_id:item.two_process_id,
                    sort:item.sort,
                    unit_price:item.unit_price,
                    due_price:item.due_price,
                    remark:item.remark,
                    GongxuSon:item.GongxuSon
                })
                this.newProcessList['_' + item.two_process_id] = item;
                if (item.process_id == 3) {
                    this.newLoomTwoProcessList = item.GongxuSon;
                    this.newLoomTwoProcessIdList = item.GongxuSon.map(item1=>{
                        return item1.id
                    })
                }
            })
            this.form.process_data = processData
            let nb = this.form.process_data.filter(e => e.process_id === 7).length;
            if(nb==1){
                this.form.process_data.map(item=>{
                    if(item.process_id == 7){
                    res.data.suitProportioning.map(item1=>{
                        item1.accessories_data.map(item2=>{
                            item2.two_process_id = item.two_process_id
                        })
                    })
                    }
                })
            }
			// this.form.process_data = res.data.goodsProcess
            // let haveNum = this.form.process_data.filter(e => e.process_id === 7).length;
            // if(haveNum==1){
            //     this.form.process_data.map(item=>{
            //         if(item.process_id == 7){
            //             this.form.suitProportioning.map(item1=>{
            //                 item1.accessories_data.map(item2=>{
            //                     item2.two_process_id = item.two_process_id
            //                 })
            //             })
            //         }
            //     })
            // }
			this.form.goods_location_data = res.data.goodsSpec
            if(res.data.goodsSpec!=''){
                res.data.goodsSpec.map(item=>{
                    let a = item.dahuo_size
                    this.location.dahuo_size = a
                })
            }else{
                this.location.dahuo_size = []
                this.form.goods_location_data = []
                res.data.gross_weight.map(item=>{
                    this.tiaoma = res.data.title
                    this.location.dahuo_size.push({
                        size_name:item.size,
                        size:'',
                    })
                })
            }
            var a = await this.$API.goods.getGoodsTypeLists.type.get({id:data.cate_id});
            this.paper = a.data;
			this.form.paper_sample_url = res.data.paper_sample_url
			this.form.ziliao_url = res.data.ziliao_full_url
			this.form.ziliao_url_name = res.data.ziliao_url_name
            let totalWu = 0
            let totalFu = 0
            res.data.suitProportioning.map(item=>{
                item.material_spec.map(item1=>{
                    totalWu = Number(item1.estimated_price) + totalWu
                })
                item.wuNumber = (totalWu).toFixed(2)
                this.wuNumber = (totalWu).toFixed(2)
                item.accessories_data.map(item1=> {
                    totalFu = Number(item1.estimated_price) + totalFu
                })
                item.fuNumber = (totalFu).toFixed(2)
                this.fuNumber = (totalFu).toFixed(2)
            })
            this.gongNumber = res.data.goods_process_price_total
		},
        // 客户
        async custChange(row){
            var res = await this.$API.all.brand.get({custom_id:row.custom_id});
            row.pingType = res.data;
            row.brand_id = ""
        },
        // 色位
        async getColorPosition(){
            var res = await this.$API.all.colorPosi.get();
            this.colorPosition = res.data;
        },
        // 商品工序
        async getGoodsProcess(){
            var res = await this.$API.all.getGoodsPro.get();
            this.goodsProList = res.data;
        },
        // 二次工序
        async getTwiceProcess(){
            var res = await this.$API.all.process.get({pid:7});
            this.twiceList = res.data;
        },
        async getBasicProcess(){
            var res = await this.$API.develop.template.lists.get();
            let data = res.data.extend.default_process_list
            let array = []
            data.map(item=>{
                array.push({
                    process_id:item.process_id,
                    process_title:item.process_title,
                    unit_price:item.price,
                    sort:item.sort,
                    GongxuSon:item.GongxuSon,
                    two_process_id:item.two_process_id,
                    due_price:0,
                })
                if (item.process_id == 3) {
                    this.newLoomTwoProcessList = item.GongxuSon;
                    this.newLoomTwoProcessIdList = item.GongxuSon.map(item1=>{
                        return item1.id
                    })
                }
            })
            if(this.mode=='add'){
                this.form.process_data = array
            }
        },
        // 获取商品类别
        async getType(){
            var res = await this.$API.all.type.get();
            this.proType = res.data;
        },
        // 所有客户
        async getKeHu(){
            var res = await this.$API.all.customer.get();
            this.customList = res.data;
        },
        //所有针种
        async getNeedle(){
            var res = await this.$API.all.needle.get();
            this.needleList = res.data;
        },
        //所有颜色
        async getColor(){
            var res = await this.$API.all.color.get();
            this.colorList = res.data;
        },
        // 洗水方式
        async getWash(){
            var res = await this.$API.all.wash.get();
            this.washList = res.data;
        },
        //大货跟单
        async getStaff(){
            var res = await this.$API.all.staff.get({job_code:100009});
            this.staffList = res.data;
        },
        //样品跟单
        async getYang(){
            var res = await this.$API.all.staff.get({job_code:100008});
            this.yangList = res.data;
        },
        //吓数员工
        async getXia(){
            var res = await this.$API.all.staff.get({job_code:100012});
            this.scareList = res.data;
        },
        //画花员工
        async getHua(){
            var res = await this.$API.all.staff.get({job_code:100013});
            this.paintedList = res.data;
        },
        // 所有款式
        async getStyle(){
            var res = await this.$API.goods.getAllGoodsStyle.get();
            this.styleList = res.data;
        },
        // 所有工序
        async getProcess(){
            var res = await this.$API.all.process.get({pid:0});
            this.processList = res.data;
        },
        // 所有部位
        async getPosition(){
            var res = await this.$API.goods.getAllGoodsPosition.get();
            this.positionList = res.data;
        },
        // 所有成分
        async getComponent(){
            var res = await this.$API.all.component.get();
            // this.componentList = res.data;
            let array = []
            res.data.map(item=>{
                array.push({
                    id:item.id,
                    component_name: item.component_detail != "" ? item.component_name + " + " + item.component_detail : item.component_name
                })
            })
            this.componentList = array
        },
        // 毛料
        openWu(item,index,row,index1){
            this.type = 1
            this.dialog.save = true
            this.$nextTick(() => {
                let a = {
                    row:row,
                    index1:index1,
                    item:item,
                    index:index
                }
                this.$refs.saveDialog.open('add').setData(a)
            })
        },
        // 辅料
        openWuFu(item,index,row,index1){
            this.type = 2
            this.dialog.save = true
            this.$nextTick(() => {
                let a = {
                    row:row,
                    index1:index1,
                    item:item,
                    index:index
                }
                this.$refs.saveDialog.open('add').setData(a)
            })
        },
        // 物辅料返回
        handleSuccess(data, mode,index1,row,item,index) {
            let a = []
            data.map((item)=>{
                a.push({
                    material_id:item.material.material_id,
                    material_spec_code:item.spec_code,
                    skc:item.skc,
                    category_name:item.material.category_name,
                    material_name:item.material.material_name,
                    color_number:item.color_number,
                    colour:item.colour,
                    remark:item.remark,
                    unit:item.material.unit_name,
                    apply_name:item.material.referred_as,
                    image:item.image_arr,
                    reference_price:item.price,
                    color_position:mode==1?row.color_position:'',
                    color_position_title:mode==1?row.color_position_title:'',
                    loss_ratio:item.material.loss_ratio
                })
            })
            let existingIds = item.material_spec.map(item => item.material_spec_code);
            for(let i = a.length - 1; i >= 0; i--){
                if(existingIds.includes(a[i].material_spec_code)){
                    a.splice(i, 1);
                }
            }
            let existingIds1 = item.accessories_data.map(item => item.material_spec_code);
            for(let i = a.length - 1; i >= 0; i--){
                if(existingIds1.includes(a[i].material_spec_code)){
                    a.splice(i, 1);
                }
            }
            if(mode==1){
                if(a[0] !=undefined){
                    item.material_spec[index] = a[0]
                    this.matColorChange(item,row)
                // }else {
                //     this.$alert('选择了重复的物料', "提示", {type: 'error'})
                }
            }else{
                item.accessories_data = [...item.accessories_data,...a]
            }
        },
        // 打开工序
        openGong(row,index){
            console.log('row :>> ', row);
            console.log('index :>> ', index);
            this.gong.save = true
			this.$nextTick(() => {
				this.$refs.gongDialog.open('add').setData({index:index})
			})
        },
        // 工序返回
        gongSuccess(data) {
            this.form.process_data = []
            data[0].detail.map(item=>{
                this.form.process_data.push({
                    process_id:item.process_id,
                    process_title:item.process_title,
                    unit_price:item.price,
                    sort:item.sort,
                    GongxuSon:item.GongxuSon,
                    two_process_id:item.two_process_id,
                    due_price:0,
                })
            })
		},
        // 纸样
        async typeChange(e){
            this.form.suitGross.map(item1=>{
                item1.gross_weight = []
            })
            this.form.sample_size = ""
            this.form.paper_sample_size = ""
            var res = await this.$API.goods.getGoodsTypeLists.type.get({id:e});
            this.paper = res.data;
            this.location.dahuo_size = []
            this.form.goods_location_data = []
            res.data.sample_clothing_arr.map(item=>{
                this.form.suitGross.map(item1=>{
                    item1.gross_weight.push({
                        size:item,
                        weight:''
                    })
                })
                this.tiaoma = res.data.title
                this.location.dahuo_size.push({
                    size_name:item,
                    size:'',
                })
            })
        },
        // 尺寸信息的部位选择
        locationChange(row,index){
            this.positionList.map(item=>{
                if(row.location_id==item.id){
                    this.form.goods_location_data[index].measure_method = item.measure_way
                    this.form.goods_location_data[index].size_latitude = item.size_latitude
                    this.form.goods_location_data[index].tolerance_range = item.tolerance_range
                }
            })
        },
        // 通过跳码计算
        input(row,index){
            let sizeLen = this.form.goods_location_data[index].dahuo_size
            let sizeIndex = ""
            let minSize = 0
            for (let i = 0; i < sizeLen.length; i++) {
                if(this.form.sample_size==row.dahuo_size[i].size_name){
                    row.dahuo_size[i].size = row.yangyi_size
                    sizeIndex = i
                }
            }
            minSize = row.yangyi_size - sizeIndex * Number(row.tiaoma)
            for (let min = 0; min < sizeLen.length; min++) {
                let size =  minSize + min*Number(row.tiaoma);
                row.dahuo_size[min].size = (size).toFixed(2)
            }
        },
        async changeGong(e){
            var res = await this.$API.all.process.get({pid:e.process_id});
            e.GongxuSon = res.data
        },
        rowAdd(){
            this.form.goods_location_data.map(item=>{
                if(item.location_id==''){
                    for (const key in item.dahuo_size) {
                        item.dahuo_size[key].size = "";
                    }
                }
            })
        },
        proInput(){
            let total = 0
            this.form.process_data.map(item=> {
                total = Number(item.due_price) + total
            })
            this.gongNumber = (total).toFixed(2)
            let a = this.form.process_data.filter(e => e.process_id === 7).length;
            if(a==1){
                this.form.process_data.map(item=>{
                    if(item.process_id == 7){
                        this.form.suitProportioning.map(item1=>{
                            item1.accessories_data.map(item2=>{
                                item2.two_process_id = item.two_process_id
                            })
                        })
                    }
                })
            }else{
                this.form.suitProportioning.map(item1=>{
                    item1.accessories_data.map(item2=>{
                        item2.two_process_id = ""
                    })
                })
            }
        },
        processMethod(param){
            const { columns, data } = param
            var sums = []
            columns.forEach((column, index) => {
                sums[index] = 0
                if(column.property != undefined){
                    data.map((item) => {
                        sums[index] += Number(item[column.property])
                    })
                }
                if (index === 2) {
                    const el = <p>工序合计<br/><br/>整件合计</p> // 主要代码
                    sums[index] = el
                    return
                }
                if (index === 6) {
                    const pel = <p>{this.gongNumber}<br/><br/>{(Number(this.fuNumber) + Number(this.wuNumber) + Number(this.gongNumber)).toFixed(2)}</p> // 主要代码
                    sums[index] = pel
                    return
                }
                if(index === 0 || index === 1 || index === 3 || index === 4 || index === 5 || index === 7 || index === 8){
                    sums[index] = ""
                }
            })
            return sums
        },
        // 色位切换
        colorChange(item){
            let a = []
            this.colorPosition.map(color=>{
                item.material_proportioning.map(mater=>{
                    if(color.id==mater.color_position){
                        a.push({
                            id: mater.color_position,
                            title: color.title,
                        })
                    }
                })
            })
            let validIds = a.map(edit => edit.id)
            item.material_spec = item.material_spec.filter(item1 => (validIds.includes(item1.color_position) || item1.material_spec_code))
            a.forEach(item1=>{
                if (!item.material_spec.some(material => material.color_position === item1.id)) {
                    item.material_spec.push({
                        color_position: item1.id,
                        color_position_title: item1.title,
                    })
                }
            })
        },
        // 计算辅料
        refInputFu(item){
            let total =0
            let fuTotal = 0
            item.accessories_data.map(item1=> {
                if(item1.reference_price && item1.ratio && item1.loss_ratio){
                    item1.estimated_price = (Number(item1.ratio) * (1+item1.loss_ratio/100) * Number(item1.reference_price)).toFixed(2)
                    total = Number(item1.estimated_price) + total
                }
            })
            item.fuNumber = (total).toFixed(2)
            this.form.suitProportioning.map(item1=>{
                fuTotal = Number(item1.fuNumber) + fuTotal
            })
            this.fuNumber = (fuTotal).toFixed(2)
        },
        matColorChange(item,row){
            let test = item.material_proportioning
            let obj = {}
            let newArray = []
            test.forEach(item1=>{
                const ratio = parseFloat(item1.ratio);
                if(obj[item1.color_position]){
                    obj[item1.color_position].ratio += ratio;
                }else{
                    obj[item1.color_position] = { ...item1,ratio };
                }
            })
            newArray = Object.values(obj);
            newArray.map(x=>{
                if(x.color_position == row.color_position){
                    // let total = 0
                    item.material_spec.map(item1=> {
                        if(x.color_position == item1.color_position){
                            this.form.suitGross.map(item2=>{
                                if(item.suit_name==item2.suit_name){
                                    item2.gross_weight.map(item3=>{
                                        if(item3.size == this.form.sample_size){
                                            if(item3.weight==''){
                                                if(item1.reference_price && x.ratio){
                                                    item1.estimated_price = (Number(this.form.sample_weight) * 1.25 *Number(item1.reference_price) * Number(x.ratio/100)/1000).toFixed(2)
                                                }
                                            }else{
                                                if(x.ratio){
                                                    item1.estimated_price = (Number(item3.weight) * 1.25*Number(item1.reference_price) * Number(x.ratio/100)/1000).toFixed(2)
                                                }
                                            }
                                        }
                                    })
                                }
                            })
                        }
                    })
                    let total = 0
                    let wuTotal = 0
                    item.material_spec.map(item1=>{
                        total = Number(item1.estimated_price) + total
                    })
                    item.wuNumber = (total).toFixed(2)
                    this.form.suitProportioning.map(item1=>{
                        wuTotal = Number(item1.wuNumber) + wuTotal
                    })
                    this.wuNumber = (wuTotal).toFixed(2)
                }
            })
        },
        // 工序二级工序change 判断是不是只有一个二次工艺,如果是则把这个二次工艺的二级工序附到辅料的工艺上
        twoProChange(){
            let a = this.form.process_data.filter(e => e.process_id === 7).length;
            if(a==1){
                this.form.process_data.map(item=>{
                    if(item.process_id == 7){
                        this.form.suitProportioning.map(item1=>{
                            item1.accessories_data.map(item2=>{
                                item2.two_process_id = item.two_process_id
                            })
                        })
                    }
                })
            }else{
                this.form.suitProportioning.map(item1=>{
                    item1.accessories_data.map(item2=>{
                        item2.two_process_id = ""
                    })
                })
            }
        },
        // 套装change
        suitChange(e) {
            this.form.suitGross = []
            this.form.suitProportioning = []
            const symbols = ["A", "B", "C", "D","E","F","G","H","I","J"]
            for (let i = 0; i < e; i++) {
                let wieght = {
                    suit_name: symbols[i],
                    factory: this.form.factory_number + symbols[i],
                    gross_weight: [],
                };
                this.form.suitGross.push(wieght);
                let mater = {
                    suit_name: symbols[i],
                    factory: this.form.factory_number + symbols[i],
                    material_proportioning: [],
                    material_spec: [],
                    accessories_data: []
                };
                this.form.suitProportioning.push(mater);
            }
            if(this.form.cate_id){
                this.typeChange(this.form.cate_id)
            }
        },
        switchChange(e){
            if(e==1){
                this.form.suitGross = [{suit_name:"A",factory:"",gross_weight:[]}]
                this.form.suitProportioning = [{suit_name:"A",factory:"",material_proportioning:[],}]
            }else{
                this.form.suitGross = [{suit_name:"",factory:"",gross_weight:[]}]
                this.form.suitProportioning = [{suit_name:"",factory:"",material_proportioning:[],}]
                this.form.suit_num = 1
            }
        },
        sampleSizeChange(e){
            this.form.suitProportioning.map(item=>{
                item.material_spec.map(item1=>{
                    item1.size = e
                })
            })
        },
        // 配比表切换主工序
        mainChange(row,index){
            for (let i = 0; i < row.length; i++) {
                row[i].is_main_process = 0;
            }
            row[index].is_main_process = 1;
        }
	}
}
</script>

<style lang="scss">
.color{
    .el-form-item__label{
        color: #f00 !important;
    }
}
.el-input-group__append{
    padding: 0 2px;
}
.el-dialog__body{
    padding: 5px 20px;
}
</style>
